package com.webserver.servlet;

import com.webserver.http.HttpContext;
import com.webserver.http.HttpRequest;
import com.webserver.http.HttpResponse;
import qrcode.QRCodeUtil;

import java.io.ByteArrayOutputStream;

public class CreateQRServlet extends HttpServlet{
    public void service(HttpRequest request, HttpResponse response){
        try(ByteArrayOutputStream bsos = new ByteArrayOutputStream();){
            String content = request.getParameters("content");
            QRCodeUtil.encode(content,bsos);
            byte[]data = bsos.toByteArray();
            response.setData(data);
            response.putHeaders("Content-Type", HttpContext.getMimeType("jpg"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
